﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace ECCIT
{
    public class StatusQueue
    {
        private Queue _queue;
		private int iCount;

        public StatusQueue()
		{
            _queue = new Queue();
		}

		public void Enqueue(object queueEntry)
		{
			Queue oSyncQueue = Queue.Synchronized(this._queue);
			oSyncQueue.Enqueue(queueEntry);
			Interlocked.Increment(ref this.iCount);
		}

		public object Dequeue()
		{
			object oReturnObj = null;
			Queue oSyncQueue = Queue.Synchronized(this._queue);

			if(this.iCount > 0 && oSyncQueue.Count > 0)
			{
				oReturnObj = oSyncQueue.Dequeue();
			}

			if(oReturnObj != null)
			{
				Interlocked.Decrement(ref this.iCount);
			}
			
			return oReturnObj;
		}

		public object Peek()
		{
			object oReturnObj = null;
			Queue oSyncQueue = Queue.Synchronized(this._queue);

			if(this.iCount > 0 && oSyncQueue.Count > 0)
			{
				oReturnObj = oSyncQueue.Peek();
			}
			
			return oReturnObj;
		}

		public int Count
		{
			get
			{
				return this.iCount;
			}
		}

		public int InternalQueueCount
		{
			get
			{
				Queue oSyncQueue = Queue.Synchronized(this._queue);

				return oSyncQueue.Count;
			}
		}
    }
}
